package echat.future.cn.echat.video;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.xiao.nicevideoplayer.NiceVideoPlayer;
import com.xiao.nicevideoplayer.NiceVideoPlayerManager;
import com.xiao.nicevideoplayer.TxVideoPlayerController;

import echat.future.cn.echat.R;
import lumingweihua.future.cn.baselibgxh.utils.ImageUtils;

/**
 * Created by Administrator on 2018/7/13.
 */

public class PlayVideoActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_play_video);
        init();
    }

    private NiceVideoPlayer mNiceVideoPlayer;
    private void init() {

        mNiceVideoPlayer = (NiceVideoPlayer) findViewById(R.id.nice_video_player);
        mNiceVideoPlayer.setPlayerType(getIntent().getIntExtra("way", NiceVideoPlayer.TYPE_IJK)); // or NiceVideoPlayer.TYPE_NATIVE
        mNiceVideoPlayer.setUp(getIntent().getStringExtra("url"), null);

        TxVideoPlayerController controller = new TxVideoPlayerController(this);
        controller.setTitle(getIntent().getStringExtra("title"));
        ImageLoader.getInstance().displayImage(getIntent().getStringExtra("image"), controller.imageView(), ImageUtils.imgOptionsSmall);
        mNiceVideoPlayer.setController(controller);
        mNiceVideoPlayer.start();
    }

    @Override
    protected void onStop() {
        super.onStop();
        // 在 onStop 时释放掉播放器
        NiceVideoPlayerManager.instance().releaseNiceVideoPlayer();
    }
    @Override
    public void onBackPressed() {
        // 在全屏或者小窗口时按返回键要先退出全屏或小窗口，
        // 所以在 Activity 中 onBackPress 要交给 NiceVideoPlayer 先处理。
        if (NiceVideoPlayerManager.instance().onBackPressd()) return;
        super.onBackPressed();
    }

}
